package com.omybug.study.config;

import com.omybug.study.condition.LinuxCondition;
import com.omybug.study.condition.WindowsCondition;
import com.omybug.study.entity.Car;
import com.omybug.study.entity.MyFactoryBeanPostProcessor;
import com.omybug.study.entity.People;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * @author: omybug
 * @date: 18/9/16 21:49
 */
@Configuration
// 指定扫描规则
//@ComponentScan(value = "com.omybug.study", includeFilters = {@ComponentScan.Filter(type=FilterType.ANNOTATION, classes = {Controller.class})}, useDefaultFilters = false)
//@Import({Car.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
//@ComponentScan(value = "com.omybug.study")
public class BeanConfig {

    @Bean
    public MyFactoryBeanPostProcessor myFactoryBean(){
        return new MyFactoryBeanPostProcessor();
    }

    @Bean
    public CarFactoryBean carFactoryBean(){
        return new CarFactoryBean();
    }

    @Bean
    public People people(){
        System.out.println("People");
        People people = new People();
        people.setAge(18);
        people.setName("赵子龙");
        return people;
    }

    @Bean("peoplex")
    public People people2(){
        People people = new People();
        people.setAge(18);
        people.setName("赵子龙");
        return people;
    }

    @Conditional(WindowsCondition.class)
    @Bean("windows")
    public People windows(){
        People people = new People();
        people.setAge(18);
        people.setName("windows");
        return people;
    }

    @Conditional(LinuxCondition.class)
    @Bean("linux")
    public People linux(){
        People people = new People();
        people.setAge(18);
        people.setName("linux");
        return people;
    }
}
